package cn.jn.lhm.vod.handler;

import cn.jn.lhm.utils.R;
import cn.jn.lhm.vod.service.VodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author LHM
 * @Tips 热爱每一天，奋斗每一天
 * @date 2020/6/7 - 21:15
 */
@RestController
@RequestMapping("/vod")
@Slf4j
public class VodHandler {

    @Resource
    private VodService vodService;

    @GetMapping("/get/play/auth/{id}")
    public R getPlayAuth(@PathVariable("id")String id){
        String authCode = vodService.getPlayAuth(id);
        return R.ok().data("auth", authCode);
    }


    @PostMapping("/upload")
    public R uploadVideo(MultipartFile file){
        log.info("start uploadVod *******时间为：" + new Date());
        String videoId =  vodService.uploadVideoToAliyun(file);
        return R.ok().data("data", videoId);
    }


    @DeleteMapping("/deleteVod/{id}")
    public R deleteVodById(@PathVariable("id")String id){
        log.info("start deleteVod *******时间为：" + new Date());
        try {
            vodService.deleteAliyunVodById(id);
            return R.ok();
        }catch (Exception e){
            return R.error();
        }
    }

    @DeleteMapping("/batch/delete")
    public R deleteBatch(@RequestParam("videoIds") List<String> videoIdList){
        vodService.removeVideoBatch(videoIdList);
        return R.ok();
    }
}
